#include <iostream>
#include <thread>
#include <atomic>
#include <mutex>
thread_local int num = 0;
static int num1 = 0;
static std::atomic <int> num2{0};
std::mutex m;
int main()
{

    auto f = [&]()
    {
        std::this_thread::sleep_for (std::chrono::milliseconds(1000));
        std::lock_guard<std::mutex> lock(m);
        num++;
        num1++;
        num2++;
        std::cout << std::this_thread::get_id()<<" "<< num << " " <<num1<<" "<<num2<<std::endl;
    };
    std::thread t1(f);
    std::thread t2(f);
    std::thread t3(f);
    t1.join();
    t2.join();
    t3.join();
}